/*
 * @lc app=leetcode.cn id=83 lang=javascript
 *
 * [83] 删除排序链表中的重复元素
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */

/**
 * 1. 双指针
 * 2. 如果两个指针值相同，则后指针向后移动一位，同时改变前指针节点的next指向
 * 否则： 前后指针同时向后移动
 */
var deleteDuplicates = function(head) {
    if(!head || !head.next) return head
    let pre = head
    let next = head.next
    while(next){
        if(pre.val === next.val){
            pre.next = next.next
        }else{
            pre = next
        }
        next = next.next
    }
    return head
};
// @lc code=end

